

def filter_by_train_neccessary(feature_names, label_names, label_train_neccessary):
    """
    根据 label_train_neccessary 过滤 feature_names 和 label_names。
    若 label_train_neccessary 为空或无任何匹配，则抛出 ValueError。
    """
    if not label_train_neccessary:
        raise ValueError("label_train_neccessary 为空：未指定需要训练的任何标签，程序终止。")

    # 把 [['WFT_Fx_LF'], ...] 拍平成一维集合 {'WFT_Fx_LF', ...}
    necessary_set = {lbl for sub in label_train_neccessary for lbl in sub}

    new_feature_names, new_label_names = [], []

    for feats, lbls in zip(feature_names, label_names):
        # 如果该行至少有一个标签在白名单里，就保留
        if any(lbl in necessary_set for lbl in lbls):
            new_feature_names.append(feats)
            new_label_names.append(lbls)

    if not new_label_names:
        raise ValueError("没有任何标签匹配 label_train_neccessary，程序终止。")

    # 额外安全检查：确保结果确实都在白名单里
    assert all(lbls[0] in necessary_set for lbls in new_label_names)

    return new_feature_names, new_label_names
